package tako.wisers.com.android.apis.activity;

import java.util.ArrayList;

import tako.wisers.com.android.apis.R;
import tako.wisers.com.android.apis.adapter.LuckyDrawAdapter;
import tako.wisers.com.android.apis.http.StationService;
import tako.wisers.com.android.apis.item.StationItem;
import tako.wisers.com.android.apis.util.Global;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class LuckyDrawActivity extends Activity implements
OnItemClickListener{
	private double mLat;
	private double mLnt;
	
	private LuckyDrawAdapter mAdapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.lucky_draw);

		ListView listView = (ListView) findViewById(R.id.location_list);
		Intent intent = getIntent();
		mLat = intent.getDoubleExtra(Global.LATITUDE_E6_EXTRA, -1);
		mLnt = intent.getDoubleExtra(Global.LONGITUDE_E6_EXTRA, -1);
		StationService stationService = new StationService();
		ArrayList<StationItem> luckyList = stationService.getLuckyItems(mLat,
				mLnt);
		mAdapter = new LuckyDrawAdapter(this, luckyList);
		listView.setAdapter(mAdapter);
		listView.setOnItemClickListener(this);
		System.gc();
	}
	
	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int position,
			long id) {
		Intent intent = new Intent();
		intent.putExtra(Global.LATITUDE_E6_EXTRA, mLat);
		intent.putExtra(Global.LONGITUDE_E6_EXTRA, mLnt);
		intent.setClass(this, LuckyDrawResultActivity.class);
		startActivity(intent);
		finish();
	}

}
